(* Test, envoyer les bonnes infos pour calend.ml en pipe *)

(* #load "unix.cma";; *)

let dec7 = function
  | 0 -> 1,0,1,1,1,1,1 
  | 1 -> 0,0,0,0,1,1,0 
  | 2 -> 0,1,1,1,0,1,1 
  | 3 -> 0,1,0,1,1,1,1 
  | 4 -> 1,1,0,0,1,1,0
  | 5 -> 1,1,0,1,1,0,1 
  | 6 -> 1,1,1,1,1,0,1 
  | 7 -> 0,0,0,0,1,1,1 
  | 8 -> 1,1,1,1,1,1,1 
  | 9 -> 1,1,0,1,1,1,1
  | _ -> failwith "dec7";;
  
let whattimeisit () = 
  Unix.localtime (Unix.time ());;

let set_tab_of_time tab t = 
  (* assert tab is a 84-length bool array *)
  let set index v =
    let a,b,c,d,e,f,g = dec7 v in
    begin
      tab.(index)   <- a;
      tab.(index+1) <- b;
      tab.(index+2) <- c;
      tab.(index+3) <- d;
      tab.(index+4) <- e;
      tab.(index+5) <- f;
      tab.(index+6) <- g;
    end
  in
  begin
    set 0 (t.Unix.tm_sec mod 10);
    set 7 (t.Unix.tm_sec / 10);
    set 14 (t.Unix.tm_min mod 10);
    set 21 (t.Unix.tm_min / 10);
    set 28 (t.Unix.tm_hour mod 10);
    set 35 (t.Unix.tm_hour / 10);
  end;;

let _ = 
  let t = Array.make 42 0 in
  while true do
    ignore(Unix.select [] [] [] 0.5);
    set_tab_of_time t (whattimeisit ());
    Array.iter print_int t;
    Printf.printf "\n";
    flush stdout
  done;;

